home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / src / bsdname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  2.2 KB  |  101 lines

  1. #include"capalloc.h"
  2. #include"capstdio.h"
  3. #include <copyright.h>
  4. #include <stdio.h>
  5. #include <wattcp.h>
  6. #include <stdlib.h>    /* itoa */
  7. #include <string.h>
  8. #include <elib.h>
  9.  
  10.  
  11. getpeername( tcp_Socket *s, void *dest, int *len )
  12. {
  13.     struct sockaddr temp;
  14.     int ltemp;
  15.  
  16.     memset( &temp, 0, sizeof( struct sockaddr ));
  17.     temp.s_ip = s->hisaddr;
  18.     temp.s_port = s->hisport;
  19.  
  20.     if (!s->hisaddr || !s->hisport || ! _chk_socket( s )) {
  21.         if (len) *len = 0;
  22.         return( -1 );
  23.     }
  24.  
  25.     /* how much do we move */
  26.     ltemp = (len) ? *len : sizeof( struct sockaddr );
  27.     if (ltemp > sizeof( struct sockaddr)) ltemp = sizeof( struct sockaddr );
  28.     qmove( &temp, dest, ltemp );
  29.  
  30.     if (len) *len = ltemp;
  31.     return( 0 );
  32. }
  33.  
  34. getsockname(  tcp_Socket *s, void *dest, int *len )
  35. {
  36.     struct sockaddr temp;
  37.     int ltemp;
  38.  
  39.     memset( &temp, 0, sizeof( struct sockaddr ));
  40.     temp.s_ip = s->myaddr;
  41.     temp.s_port = s->myport;
  42.  
  43.     if (!s->hisaddr || !s->hisport || ! _chk_socket( s )) {
  44.     if (len) *len = 0;
  45.     return( -1 );
  46.     }
  47.  
  48.     /* how much do we move */
  49.     ltemp = (len) ? *len : sizeof( struct sockaddr );
  50.     if (ltemp > sizeof( struct sockaddr)) ltemp = sizeof( struct sockaddr );
  51.     qmove( &temp, dest, ltemp );
  52.  
  53.     if (len) *len = ltemp;
  54.     return( 0 );
  55. }
  56.  
  57. char *getdomainname( char *name, int length )
  58. {
  59.     if ( length ) {
  60.     if ( length < strlen( def_domain ))
  61.         *name = 0;
  62.     else
  63.         strcpy( name, def_domain );
  64.     return( name );
  65.     }
  66.     return( ( def_domain && *def_domain ) ? def_domain : NULL );
  67. }
  68.  
  69. char *setdomainname( char *string )
  70. {
  71.     return( def_domain = string );
  72. }
  73.  
  74. char *gethostname( char *name, int len )
  75. {
  76.     if ( len ) {
  77.     if (len < strlen( _hostname ))
  78.         *name = 0;
  79.     else
  80.         strcpy( name, _hostname );
  81.     return( name );
  82.     }
  83.     return( ( _hostname && *_hostname ) ?  _hostname  : NULL );
  84. }
  85. char *sethostname( char *name )
  86. {
  87.     return( _hostname = name );
  88. }
  89. void psocket( tcp_Socket *s )
  90. {
  91.     char buffer[255];
  92.  
  93.     outch( '[' );
  94.     outs( inet_ntoa( buffer, s->hisaddr) );
  95.     outch( ':' );
  96.     itoa( s->hisport, buffer, 10 );
  97.     outs( buffer );
  98.     outch( ']' );
  99.  
  100. }
  101.